#!/usr/bin/env python
# -*- coding:utf-8 -*-
# Create by zhang
# Create on 2022/7/6 15:05
from pandas import DataFrame, Series


def normalize_max_min2(df:DataFrame, keys:list):
    """
    最大最小标准化（Min-Max Normalization）
    """
    if keys is not None and len(keys) > 0:
        for key in keys:
            if key in df.keys():
                max_v = df[key].max()
                min_v = df[key].min()
                d_v = max_v - min_v
                df[key] = (df[key] - min_v) / d_v


def normalizeMaxMin1(data:Series):
    """
    最大最小标准化（Min-Max Normalization）
    """
    max_v = data.max()
    min_v = data.min()
    d_v = max_v - min_v
    return (data - min_v)/d_v


def normalize_z_score(df:DataFrame, keys:list):
    """
     z-score 标准化(zero-mean normalization)：将数据按期属性（按列进行）减去其均值，并除以其标准差。
     Z-Score的主要目的就是将不同量级的数据统一转化为同一个量级，统一用计算出的Z-Score值衡量，以保证数据之间的可比性。
     ${\rm Z} = \frac{{x - \mu }}{\sigma }$
    """
    if keys is not None and len(keys) > 0:
        for key in keys:
            if key in df.keys():
                mean = df[key].mean()
                std = df[key].std()
                df[key] = (df[key] - mean) / std